From: Yehuda Katz Date: Fri, 9 May 2014 00:50:28 +0000 (-0700) Subject: Clean up process DSL in tests X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~1068 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=7983a5fd167591dcfb082d2b86ab00034d988951;p=cargo.git Clean up process DSL in tests --- diff --git a/tests/support.rs b/tests/support.rs index 72ae985d0..cae03d45b 100644 --- a/tests/support.rs +++ b/tests/support.rs @@ -66,9 +66,11 @@ impl ProjectBuilder { } pub fn cargo_process(&self, program: &str) -> ProcessBuilder { - process(program) - .cwd(self.root()) - .extra_path(cargo_dir()) + self.build(); + + process(program) + .cwd(self.root()) + .extra_path(cargo_dir()) } pub fn file(mut self, path: B, body: &str) -> ProjectBuilder { @@ -77,7 +79,7 @@ impl ProjectBuilder { } // TODO: return something different than a ProjectBuilder - pub fn build(self) -> ProjectBuilder { + pub fn build<'a>(&'a self) -> &'a ProjectBuilder { match self.build_with_result() { Err(e) => fail!(e), _ => return self @@ -208,7 +210,7 @@ impl ham::Matcher for Execs { match res { Ok(out) => self.match_output(&out), - Err(_) => Err("could not exec process".to_owned()) + Err(_) => Err(format!("could not exec process {}", process)) } } } diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 93fa0ff0b..f3e88d94e 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -1,6 +1,7 @@ use support::{ResultTest,project,execs}; use hamcrest::{assert_that,existing_file}; use cargo; +use cargo::util::process; fn setup() { } @@ -18,25 +19,32 @@ test!(cargo_compile { name = "foo" "#) - .file("src/foo.rs", r#" - fn main() { - println!("i am foo"); - } - "#) - .build(); - - p.cargo_process("cargo-compile") - .args([]) - .exec_with_output() - .assert(); + .file("src/foo.rs", main_file(r#""i am foo""#, [])); + assert_that(p.cargo_process("cargo-compile"), execs()); assert_that(&p.root().join("target/foo"), existing_file()); + let target = p.root().join("target"); + assert_that( - cargo::util::process("foo").extra_path(p.root().join("target")), + process("foo").extra_path(target), execs().with_stdout("i am foo\n")); }) +fn main_file(println: &str, deps: &[&str]) -> ~str { + let mut buf = StrBuf::new(); + + for dep in deps.iter() { + buf.push_str(format!("extern crate {};\n", dep)); + } + + buf.push_str("fn main() { println!("); + buf.push_str(println); + buf.push_str("); }\n"); + + buf.to_owned() +} + test!(cargo_compile_with_nested_deps { let mut p = project("foo"); let bar = p.root().join("bar"); @@ -61,13 +69,7 @@ test!(cargo_compile_with_nested_deps { name = "foo" "#) - .file("src/foo.rs", r#" - extern crate bar; - - fn main() { - println!("{}", bar::gimme()); - } - "#) + .file("src/foo.rs", main_file(r#""{}", bar::gimme()"#, ["bar"])) .file("bar/Cargo.toml", r#" [project] @@ -105,8 +107,7 @@ test!(cargo_compile_with_nested_deps { pub fn gimme() -> ~str { "test passed".to_owned() } - "#) - .build(); + "#); p.cargo_process("cargo-compile") .exec_with_output()